package com.model;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Shoe {

	private List<Card> shoe = new LinkedList<Card>();
	private int numberOfDecks = 1;
	
	public Shoe () {
		this(1);
	}
	
	public Shoe(int numberOfDecks) {
		if (numberOfDecks > 0) {
			this.numberOfDecks  = numberOfDecks;
		}
		newShoe();
	}
	
	public Card getCard() {
		if (shoe.isEmpty()) {
			newShoe();
		}
		
		Card card = shoe.get(0);
		shoe.remove(0);
		return card;
	}
	
	public List<Card> getCards() {
		return shoe;
	}
	
	public int size() {
		return shoe.size();
	}
	
	public void emptyShoe() {
		shoe.clear();
	}
	
	public void newShoe() {
		emptyShoe();
		int tempNumberOfDecks = numberOfDecks;
		while (tempNumberOfDecks > 0) {
			shoe.addAll(new Deck().getDeckofCards());
			tempNumberOfDecks--;
		}
		shuffle();
	}

	public void shuffle() {
		Collections.shuffle(shoe);
	}	
	
	public int getShoeTotalValue() {
		int totalvalue = 0;
		for (Card card : shoe) {
			totalvalue += card.getValue();
		}
		
		return totalvalue;
	}
	
	public String toString() {
		return shoe.toString();
	}

}
